package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type CategoryRequest struct {
	Title    string `valid:"title" json:"title"`
	Sort     int8   `valid:"sort" json:"sort"`
	Status   int8   `valid:"status" json:"status"`
	ParentID uint64 `valid:"parent_id" json:"parent_id"`
	ZoneID   uint64 `valid:"zone_id" json:"zone_id"`
}

func CategoryStore(data interface{}, c *gin.Context) map[string][]string {

	rules := govalidator.MapData{
		"title":     []string{"required", "min:1", "max:10"},
		"sort":      []string{"numeric"},
		"status":    []string{"in:0,1"},
		"parent_id": []string{"required"},
		"zone_id":   []string{"required"},
	}
	messages := govalidator.MapData{
		"title": []string{
			"required:标题为必填项",
			"min:标题长度需大于 1",
			"max:标题长度需小于 40",
		},
		"sort": []string{
			"numeric:排序取值不合法",
		},
		"status": []string{
			"in:状态取值不合法",
		},
		"parent_id": []string{
			"required:参数缺失",
		},
		"zone_id": []string{
			"required:状态取值不合法",
		},
	}

	return validate(data, rules, messages)
}
